﻿using LoveEat.API.Write.Applications.Commands.Aquaculture;
using LoveEat.Domain.Aquaculture;
using LoveEat.ErrorCode;
using LoveEat.Infrastructure.Interfaces;
using MediatR;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace LoveEat.API.Write.Applications.CommandHandlers.Aquaculture
{
    public class DeleteHealthCommandHandler : IRequestHandler<DeleteHealthCommand, APIResult<int>>
    {
        private readonly IBaseRespository<HealthModel> healRep;

        public DeleteHealthCommandHandler(IBaseRespository<HealthModel> healRep)
        {
            this.healRep = healRep;
        }
        public async Task<APIResult<int>> Handle(DeleteHealthCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result=new APIResult<int>();
            result.Code=APIResultCode.删除成功;
            result.Message=APIResultCode.删除成功.ToString();

            var res = healRep.GetAll().FirstOrDefault(x=>x.HealthId==request.HealthId);
            res.IsDelete=true;  
            await healRep.UpdateAsync(res);


            return await Task.FromResult(result);
        }
    }
}
